package cn.signalpha.modules.shop.controller.admin;

import cn.signalpha.common.constant.AppConstant;
import cn.signalpha.core.boot.ctrl.BaseController;
import cn.signalpha.core.mp.support.Condition;
import cn.signalpha.core.mp.support.Query;
import cn.signalpha.core.tool.api.R;
import cn.signalpha.core.tool.utils.Func;
import cn.signalpha.modules.shop.entity.GoodsBrand;
import cn.signalpha.modules.shop.service.GoodsBrandService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.*;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * 控制器
 *
 * @author signalpha
 */
@RestController
@AllArgsConstructor
@RequestMapping(AppConstant.APPLICATION_SHOP_NAME + "/admin/goods/brand")
@Api(value = "商品品牌", tags = "商品品牌")
public class GoodsBrandController extends BaseController {

	private final GoodsBrandService goodsBrandService;

    @GetMapping("/page")
    @ApiImplicitParams({
        @ApiImplicitParam(name="name", dataType = "string", value = "名称"),
        @ApiImplicitParam(name="status", dataType = "string", value = "状态"),
        @ApiImplicitParam(name="categoryId", dataType = "string", value = "分类id"),
    })
    @ApiOperation(value = "分页", notes = "")
    public R<IPage<GoodsBrand>> page(@ApiIgnore @RequestParam Map<String, Object> params, Query query) {
        QueryWrapper<GoodsBrand> wrapper = goodsBrandService.selectGoodsBrandWrapper(params);
        return R.data(goodsBrandService.page(Condition.getPage(query), wrapper));
    }

    @GetMapping("/list")
	@ApiImplicitParams({
		@ApiImplicitParam(name="name", dataType = "string", value = "名称"),
		@ApiImplicitParam(name="status", dataType = "string", value = "状态"),
		@ApiImplicitParam(name="categoryId", dataType = "string", value = "分类id"),
	})
    @ApiOperation(value = "列表", notes = "")
    public R<List<GoodsBrand>> list(@ApiIgnore @RequestParam Map<String, Object> params) {
        return R.data(goodsBrandService.list(goodsBrandService.selectGoodsBrandWrapper(params)));
    }

	@GetMapping("/info")
	@ApiOperation(value = "详情", notes = "传入id")
	public R<GoodsBrand> info(@ApiParam(value = "主键", required = true) @RequestParam Long id) {
		return R.data(goodsBrandService.getById(id));
	}

    @PostMapping("/submit")
    @ApiOperation(value = "提交", notes = "传入goodsBrand")
    public R submit(@Valid @RequestBody GoodsBrand goodsBrand) {
        return R.status(goodsBrandService.saveOrUpdate(goodsBrand));
    }

	@PostMapping("/remove")
	@ApiOperation(value = "删除", notes = "传入ids")
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.status(goodsBrandService.removeByIds(Func.toLongList(ids)));
	}

}
